<?php

namespace Acme\CommonBundle\Service;

use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Acme\UserBundle\Helper\UploadHandler;
use Acme\PersonBundle\Entity\Personimage;
use Acme\PinnwandBundle\Entity\Pinnwand;
use Acme\PinnwandBundle\Entity\Pinnwandgalerie;
use Acme\EventBundle\Entity\Information;
use Acme\EventBundle\Entity\Feedback;
use Doctrine\ORM\EntityRepository;

class Mail {
	private $context;
	private $em;
	public function __construct(SecurityContext $context,\Doctrine\ORM\EntityManager $em) {
		$this->context = $context;
		$this->em = $em;
	}
	public function sendMail($subject, $message, $email_to) {
		// für HTML-E-Mails muss der 'Content-type'-Header gesetzt werden
		$header = 'MIME-Version: 1.0' . "\r\n";
		$header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
		// zusützliche Header
		$header .= 'To: SELV-book <info@eisen-leger.ch>' . "\r\n";
		$header .= 'From: SELV-book <info@eisen-leger.ch>' . "\r\n";
		// $header .= 'Cc: miguel@closas.ch' . "\r\n";
		$header .= 'Bcc: ' . $email_to . "\r\n";
		// verschicke die E-Mail
		
		mail ( 'info@eisen-leger.ch', $subject, $message, $header );
	}
	private function getUser() {
		return $this->context->getToken ()->getUser ();
	}
	private function getEntityManager() {
		return $this->em;
	}
	public function checkActuellInformation($new_information) {
		$informations = $this->getEntityManager ()->getRepository ( 'AcmeEventBundle:Information' )->findAll ();
		
		foreach ( $informations as $information ) {
			if ($information->getId () != $new_information->getId ()) {
				if ($information->getActuellInformation () == 1) {
					$information->setActuellInformation ( 2 );
					$this->getEntityManager ()->persist ( $information );
					$this->getEntityManager ()->flush ();
				}
			}
		}
	}
}